import os
from pathlib import Path

HERE_PATH = os.path.dirname(__file__)
os.chdir(HERE_PATH)
MUSIC_DIR = Path('d:/Music/Staging')


def exec_ncmdump(file_path: str):
    cmd = f'ncmdump.exe "{file_path}"'
    os.system(cmd)
    print(f'NCM --> [ {file_path} ].')


filtered_list = MUSIC_DIR.glob('*.ncm')
convert_counter = 0
total = 0

for f in filtered_list:
    total += 1
    corresponding_mp3_name = f.stem + '.mp3'
    corresponding_mp3_path = f.parent / corresponding_mp3_name
    if corresponding_mp3_path.exists():
        continue
    exec_ncmdump(f.as_posix())
    convert_counter += 1

print(f'NCM file count:  {total}.')
print(f'Converted : {convert_counter}.')
os.system('pause')
